<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.css" rel="stylesheet" />
		<link href="../css/customize.css" rel="stylesheet" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left font-black"></a>
			<h1 class="mui-title">修改密码</h1>
		</header>

		<div class="mui-content mui-content-padded form-container">
			<div class="mui-content-padded">
				<p>旧密码</p>
				<div class="mui-input-row">
					<input type="password" class="mui-input-password" placeholder="请输入密码" id="oldPw"
						style="background-color: #F2F8FC;border: 0;">
				</div>
			</div>

			<div class="mui-content-padded">
				<p>新密码</p>
				<div class="mui-input-row">
					<input type="password" class="mui-input-password" placeholder="请输入密码" id="newPw"
						style="background-color: #F2F8FC;border: 0;">
				</div>

			</div>

			<div class="mui-content-padded">
				<p>再次输入</p>
				<div class="mui-input-row">
					<input type="password" class="mui-input-password" placeholder="请输入密码" id="newPw2"
						style="background-color: #F2F8FC;border: 0;">
				</div>

			</div>

			<div class="mui-content-padded">
				<button class="mui-btn mui-btn-green mui-btn-block" id="loginBtn">
					确定
				</button>
			</div>

		</div>
		<script src="../js/mui.js"></script>
		<script type="text/javascript">
			mui.init()
			let baseUrl = localStorage.getItem("ip")
			document.querySelector("#loginBtn").addEventListener("tap", function() {
				let oldPw = document.querySelector("#oldPw").value
				let newPw = document.querySelector("#newPw").value
				let newPw2 = document.querySelector("#newPw2").value
				if (oldPw.length = 0) {
					mui.toast("旧密码不能为空");
					return
				}
				if (newPw.length < 6) {
					mui.toast("新密码不可以少于六位");
					return
				}
				if (newPw.trim() !== newPw2.trim()) {
					mui.toast("确认密码与新密码不一致");
					return
				}
				mui.ajax(baseUrl + '/system/user/profile/updatePwd?oldPassword=' + oldPw + '&newPassword=' + newPw, {
					dataType: 'json', //服务器返回json格式数据
					type: 'put', //HTTP请求类型
					timeout: 10000, //超时时间设置为10秒；
					headers: {
						'Content-Type': 'application/json',
						'authorization': localStorage.getItem("token")
					},
					success: function(data) {
						if (data.code == 500) {
							mui.toast(data.msg);
						} else if (data.code == 200) {
							mui.toast("修改成功");
							mui.back()
						}
					},
					error: function(xhr, type, errorThrown) {
						console.log(errorThrown);
						console.log(JSON.stringify(xhr));
						console.log(type);
					}
				});
			})
		</script>
	</body>

</html>